package com.toweave.starter.utils;

import android.content.Context;
import static androidx.core.content.ContextCompat.getSystemService;
import static com.toweave.starter.utils.ConstantsUtil.LIZ_TAG;

import android.content.Context;
import android.graphics.Point;
import android.os.Build;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;

import com.toweave.starter.AsApplication;

import java.util.Locale;

public class DisplayUtil {
  /**
   * 将dp单位转换为px单位
   *
   * @param context Context对象，用于获取屏幕密度
   * @param dp      需要转换的dp值
   * @return 转换后的px值
   */
  public static int dpToPx(Context context, float dp) {
    if (context == null) {
      throw new IllegalArgumentException("Context must not be null.");
    }
    // 获取屏幕密度（density）值
    float density = context.getResources().getDisplayMetrics().density;
    // 进行转换
    return Math.round(dp * density);
  }

  public static float getDensity(Context context) {
    if (context == null) {
      throw new IllegalArgumentException("Context must not be null.");
    }
    // 获取屏幕密度（density）值
    return context.getResources().getDisplayMetrics().density;
  }


  public static float getMeta(Context context) {
    String manufacturer = Build.MANUFACTURER; // 制造商
    String model = Build.MODEL; // 型号
    String brand = Build.BRAND; // 品牌
    String device = Build.DEVICE; // 设备名
    String product = Build.PRODUCT; // 产品名
    String hardware = Build.HARDWARE; // 硬件名
    String release = Build.VERSION.RELEASE; // Android系统版本号
    int sdkInt = Build.VERSION.SDK_INT; // API级别
    String securityPatch = Build.VERSION.SECURITY_PATCH; // 安全补丁程序级别
    WindowManager windowManager = getSystemService(context, WindowManager.class);
    // WindowManager windowManager = getSystemService(context, null);
    Display display = windowManager.getDefaultDisplay();
    Point size = new Point();
    display.getRealSize(size);
    int width = size.x;
    int height = size.y;
    String sDensity = String.format(Locale.CHINA, "manufacturer: %s, brand: %s, width: %d, height: %d", manufacturer, brand, width, height);
    Log.i(LIZ_TAG, sDensity);
    return 1.0F;
  }



}
